#include<bits/stdc++>
using namespace std;

// 【题目】力扣2529.正整数和负整数的最大计数
// 【难度】简单
// 【提交】https://leetcode.cn/problems/maximum-count-of-positive-integer-and-negative-integer/submissions/669087408/?envType=problem-list-v2&envId=binary-search
// 【标签】数组；二分查找；计数

class Solution {
public:
    int lowerBound(vector<int>& nums, int val) {
        int l = 0, r = nums.size();
        while (l < r) {
            int m = (l + r) / 2;
            if (nums[m] >= val) {
                r = m;
            } else {
                l = m + 1;
            }
        }
        return l;
    }

    int maximumCount(vector<int>& nums) {
        int pos1 = lowerBound(nums, 0);
        int pos2 = lowerBound(nums, 1);
        return max(pos1, (int) nums.size() - pos2);
    }
};
